package com.aaa.java11;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/16 14:04
 * @description：
 * @modified By：
 * @version:
 */
public class StudentNew   {
   private int	id;
    private String	name;
    private  int age;
    private  Date birthday;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", birthday=" + birthday +
                '}';
    }

    public static void main(String[] args) {
       // StudentList[] students= new StudentList[5];
        List<StudentNew> studentList = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            StudentNew student= new StudentNew();
            student.setId(i+1000);
            student.setName("张三"+i);
            student.setAge(new Random().nextInt(100));
            studentList.add(student);
        }
        System.out.println("排序之前：");
        for (StudentNew student : studentList) {
            System.out.println(student);
        }
        //排序方案一：冒泡排序
       /* for (int i = 1; i <studentList.size() ; i++) {
            for (int j = 0; j < studentList.size() - i; j++) {
                if(studentList.get(j).getAge()>studentList.get(j+1).getAge()){
                    StudentNew temp1= new StudentNew();
                    StudentNew temp2= new StudentNew();
                    temp1=studentList.get(j);
                    temp2=studentList.get(j+1);
                    studentList.set(j,temp2);
                    studentList.set(j+1,temp1);
                }
            }
        }*/
       //排序方案二：实体类实现Comparable接口
/*        Collections.sort(studentList);
        System.out.println("排除之后：");
        for (StudentNew student : studentList) {
            System.out.println(student);
        }*/
        //排序方案三：自己创建Comparator比较器
      /*  MyComparator myComparator = new MyComparator();
       *//* Collections.sort(studentList,myComparator );*//*
        studentList.sort(myComparator);
        System.out.println("排除之后：");
        for (StudentNew student : studentList) {
            System.out.println(student);
        }*/
        //排序的方案四：使用stream
        System.out.println("排除之后：");
        List<StudentNew> studentNewList = studentList.stream().sorted(Comparator.comparing(StudentNew::getAge)).collect(Collectors.toList());
        for (StudentNew studentNew : studentNewList) {
            System.out.println(studentNew);
        }
    }


    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description:
     * @create time: 2022/7/16 14:24
     * @param other
     * @return
     */
   /* @Override
    public int compareTo(StudentNew other) {
        if(this.age>other.age){
            return 1;
        }
        if(this.age<other.age){
            return -1;
        }
        return 0;
    }*/
}
